/*
 *	Para Borrar una orden
 *	
 */
function deleteOrder( orderID) {
	if(currentUsr == ""){
		//mandar a la pantalla de logIN tener cuidado que hay que mandarle el product ID;
		//para que se agregue
		alert("no esta logeado\n");
	}
	/*if(currentOrderString != ""){
		alert("ya hay una orden creada");
		return;
	}*/
	var req = new Ajax.Request(
	urlorder,
	{
		method : 'post',
		parameters : {
			method : 'DeleteOrder',
			username : currentUsr,
			authentication_token: currentToken,
			order_id: orderID
		},

		onSuccess : function(transport) {
			var response = transport.responseXML || "no response text";
			if(response.getElementsByTagName("response")[0].getAttribute("status") == 'ok'){
				getOrderList();
			}
		},

		onFailure : function() {
			alert('Problems on Ajax Request')
		}
	});
}

/*
 *	Esta funcion agrega un item al una orden
 *	si esta logueado y existe una orden agrega ah�.
 *	si no crea una orden y lagrega ah�
 *	si no esta logueado manda a login --- pero no se como!!! ---
 * 	
 *	username, token y etc son variables globales.
 *	pero creo q son cookies :3
 * borrar 87 88 89 90 91 92
 * 				
 */
//var userNameString = "xin";
//var tokenString="bd4fcc97578ce33ca5fb331f42bc375";
var currentOrderString="";
//var urlcatalog = 'http://localhost:8080/service/Catalog.groovy';
var urlorder = 'http://localhost:8080/service/Order.groovy';
/****************************************************************************************************************/

function getToken(){
	var req = new Ajax.Request(
	"http://localhost:8080/service/Security.groovy",
	{
	method : 'get',
	parameters : {
		method : 'SignIn',
		username : userNameString,
		password: "12345678",
		},

		onSuccess : function(transport) {
			var response = transport.responseXML || "no response text";
			tokenString = response.getElementByTagName("token")[0].firstChild.nodeValue
		},

		onFailure : function() {
			alert('Problems on Ajax Request')
		}
	});
}
/****************************************************************************************************************/

function createOrder(){
	if(currentUsr == ""){
		//mandar a la pantalla de logIN tener cuidado que hay que mandarle el product ID;
		//para que se agregue
		alert("no esta logeado\n");
	}
	/*if(currentOrderString != ""){
		alert("ya hay una orden creada");
		return;
	}*/
	var req = new Ajax.Request(
	urlorder,
	{
	method : 'post',
	parameters : {
		method : 'CreateOrder',
		username : currentUsr,
		authentication_token: currentToken,
		},

		onSuccess : function(transport) {
			var response = transport.responseXML || "no response text";
			if(response.getElementsByTagName("response")[0].getAttribute("status") == 'ok'){
				currentOrderString = response.getElementsByTagName("order")[0].getAttribute("id");
			}
		},

		onFailure : function() {
			alert('Problems on Ajax Request')
		}
	});

}
function CreateOrderAndUpdate(productId,name){
	closePopUpOrder();
	createOrder();
	displayPopUpOrder(productId,name);
	
}
function createProductXML( productId ,cant){
	var xml;
	
	xml = "<order_item>"+
		"<product_id>" + productId + "</product_id>" +
		"<count>"+ cant + "</count>" +
		"</order_item>";
	return xml;
}
 
function addOrderItem( ordernumber, productId, cant ) {
	
	if(currentUsr == null){
		//mandar a la pantalla de logIN tener cuidado que hay que mandarle el product ID;
		displayPopLogIn();
		return;
	}
	
	//if(currentOrderString == ""){
		//no hay orden creada, crear order;
		//createOrder();
	//}
	
	var xml = createProductXML( productId, cant );

	var req = new Ajax.Request(
		urlorder,
		{
		method : 'post',
		parameters : {
			method : 'AddOrderItem',
			username : currentUsr,
			authentication_token: currentToken,
			order_id: ordernumber,
			order_item: xml
			},

			onSuccess : function(transport) {
				var response = transport.responseXML || "no response text";
				if(response.getElementsByTagName("response")[0].getAttribute("status") == 'ok'){
					displayAlert("Product Added Succesfuly");//change
				}
			},

			onFailure : function() {
				alert('Problems on Ajax Request')
			}
		});
			
}

function deleteOrderItem( productId, cant, orderID ) {
	
/*	if(userNameString == null){
		//mandar a la pantalla de logIN tener cuidado que hay que mandarle el product ID;
		alert("no esta logeado\n");
		return;
	}
	
	if(currentOrderString == ""){
		//no hay orden creada, crear order;
		createOrder();
	}
	*/
	var xml = createProductXML( productId, cant );

	var req = new Ajax.Request(
		urlorder,
		{
		method : 'post',
		parameters : {
			method : 'DeleteOrderItem',
			username : currentUsr,
			authentication_token: currentToken,
			order_id: orderID,
			order_item: xml
			},

			onSuccess : function(transport) {
				var response = transport.responseXML || "no response text";
				if(response.getElementsByTagName("response")[0].getAttribute("status") == 'ok'){
					alert("producto borrado Exitosamente");//change
				}
				getOrderDetail(orderID);
			},

			onFailure : function() {
				alert('Problems on Ajax Request')
			}
		});
			
}

function changeOrderAddress(orderId,addressId){
	var resp;
	if(currentUsr == '' || currenPass == '' || currentToken == '') {
		displayAlert('hay que loguearse antes');
		return;
	}
	
	var req = new Ajax.Request(urlorder, {
		method: 'post', 
		parameters: {method: 'ChangeOrderAddress', username: currentUsr, authentication_token: currentToken,order_id:orderId,address_id:addressId},
		onSuccess: function(transport){
			resp = transport.responseXML;
						
			if(!checkResp(resp)){
				return;
			}
			if (resp.getElementsByTagName("response")[0].getAttribute("status") == "ok"){
				alert("Se cambió con exito la dirección");
			}
			
		},
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
  });
}

/*
getOrderList = function() {
	
	var cookie;
	var resp;
	cookie = new cookiejar('tienda virtual');
	currentUsr = cookie.getCookie('username');
	currentPass = cookie.getCookie('password');
	currentToken = cookie.getCookie('token');
	
	if(currentUsr == '' || currenPass == '' || currentToken == '') {
		alert('hay que loguearse antes');
		return;
	}
	
	
	var req = new Ajax.Request(urlorder, {
		method: 'post',
		parameters: {method: 'GetOrderList', username: currentUsr, authentication_token: currentToken},
		onSuccess: function(transport){
			resp = transport.responseXML;
						
			if(!checkResp(resp)){
				return;
			}
			var mainContent = document.getElementById('mainContent');
			var orders = resp.getElementsByTagName('orders');
			// birth date
			respValue = resp.getElementsByTagName('birth_date')[0].firstChild;
			element = document.getElementsByName('birth_date');
			currentBirthDate = respValue.nodeValue;
			element[0].setAttribute('value', respValue.nodeValue);
			
		},
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
  });
}; 
*/
function getOrderList(){
	var resp;
	
	/*currentUsr = cookie.getCookie('username');
	currentPass = cookie.getCookie('password');
	currentToken = cookie.getCookie('token');*/
	/*var cookie = new cookiejar("tienda_virtual");
	alert(cookie.getCookie('username'));*/
	if(currentUsr == '' || currentToken == '') {
		diplayAlert('hay que loguearse antes');
		return;
	}
	
	var req = new Ajax.Request(urlorder, {
		method: 'get', 
		parameters: {method: 'GetOrderList', username: currentUsr, authentication_token: currentToken},
		onSuccess: function(transport){
			resp = transport.responseXML;
						
			if(!checkResp(resp)){
				return;
			}
			if (resp.getElementsByTagName("response")[0].getAttribute("status") == "ok"){
					var ordenesDiv = document.createElement("div");
					document.getElementById("mainContent").innerHTML="";
					document.getElementById("mainContent").appendChild(ordenesDiv);
					
				var Transportada = document.createElement("div");
				var Entregadas = document.createElement("div");
				var Creada = document.createElement("div");
				var Confirmada = document.createElement("div");
				
				var ordenes=resp.getElementsByTagName("order");
				if(ordenes.length == 0){
					Creada.innerHTML = "<h1> There are no orders created </h1>";
					ordenesDiv.appendChild(Creada);
					return;
				}
				for(var i = 0; i < ordenes.length; i++)
				{
					
					var ordenDiv = document.createElement("div");
					ordenDiv.setAttribute("class","ordenDiv");
					
					
					var address_id="";
					try{
						address_id = ordenes[i].getElementsByTagName("address_id")[0].firstChild.nodeValue;
					}catch(e){
					}
					var status = ordenes[i].getElementsByTagName("status")[0].firstChild.nodeValue;
					var created_date = ordenes[i].getElementsByTagName("created_date")[0].firstChild.nodeValue;
					var confirmed_date="";
					var shipped_date="";
					try{ 
						confirmed_date = ordenes[i].getElementsByTagName("confirmed_date")[0].firstChild.nodeValue;
						shipped_date = ordenes[i].getElementsByTagName("shipped_date")[0].firstChild.nodeValue;
					}catch(e){}
					var latitude = ordenes[i].getElementsByTagName("latitude")[0].firstChild.nodeValue;
					var longitude = ordenes[i].getElementsByTagName("longitude")[0].firstChild.nodeValue;
					
					ordenDiv.setAttribute("id","orden"+ordenes[i].getAttribute("id"));
					
					var ordenNumber = document.createElement('h2');
					ordenNumber.innerHTML= "Numero De Orden:" + ordenes[i].getAttribute("id");
					ordenNumber.setAttribute("onclick","getOrderDetail("+ ordenes[i].getAttribute("id") +");");
					ordenDiv.appendChild(ordenNumber);
					
					
					
					
			
					
					switch(status){
						case '4':
								var lat = document.createElement("p");
								lat.innerHTML = "Latitud " + latitude;
								ordenDiv.appendChild(lat);
								
								var log = document.createElement("p");
								log.innerHTML = "Longitud " + longitude;
								ordenDiv.appendChild(log);
								
								var date4 = document.createElement("div");
								date4.innerHTML = delivered_date;
								ordenDiv.appendChild(date4);
						case '3':
								var date3 = document.createElement("div");
								date3.innerHTML = shipped_date;
								ordenDiv.appendChild(date3);
							
						case '2':
								var date2 = document.createElement("div");
								date2.innerHTML = confirmed_date;
								ordenDiv.appendChild(date2);
							
						case '1':
								var date1 = document.createElement("div");
								date1.innerHTML = created_date;
								ordenDiv.appendChild(date1);
							break;
					}
					switch(status){
						case '4':
							ordenDiv.setAttribute("class","Transportada");
							Transportada.appendChild(ordenDiv);
							break;
						case '3':
							ordenDiv.setAttribute("class","Entregada");
							Entregadas.appendChild(ordenDiv);
							break;
						case '2':
							ordenDiv.setAttribute("class","Confirmada");
							Confirmada.appendChild(ordenDiv);
							break;
						case '1':
							ordenDiv.setAttribute("class","Creada");
							var eliminarButton = document.createElement("input");
							eliminarButton.setAttribute("type","button");
							eliminarButton.setAttribute("onClick","deleteOrder(\""+ ordenes[i].getAttribute("id") +"\");");
							eliminarButton.setAttribute("value","Eliminar");
							ordenDiv.appendChild(eliminarButton)
							Creada.appendChild(ordenDiv);
							break;
						}
					
				}
				
				var title1 = document.createElement("h1");
				title1.innerHTML = "No Confirmed Orders"
				var title2 = document.createElement("h1");
				title2.innerHTML = "Confirmed Orders"
				var title3 = document.createElement("h1");
				title3.innerHTML = "Delivered Orders"
				var title4 = document.createElement("h1");
				title4.innerHTML = "Transporded Orders"
				
				ordenesDiv.appendChild(title1);
				ordenesDiv.appendChild(Creada);
				ordenesDiv.appendChild(title2);
				ordenesDiv.appendChild(Confirmada);
				ordenesDiv.appendChild(title3);
				ordenesDiv.appendChild(Entregadas);
				ordenesDiv.appendChild(title4);
				ordenesDiv.appendChild(Transportada);
			}
			
		},
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
  });
}

function setOrdersInPopUp(){
	var resp;
	
	/*currentUsr = cookie.getCookie('username');
	currentPass = cookie.getCookie('password');
	currentToken = cookie.getCookie('token');*/
	var cookie = new cookiejar("tienda_virtual");
	/*alert(cookie.getCookie('username'));*/
	if(currentUsr == '' || currentToken == '') {
		alert('hay que loguearse antes');
		return;
	}
	
	var req = new Ajax.Request(urlorder, {
		method: 'get', 
		asynchronous:false,
		parameters: {method: 'GetOrderList', username: currentUsr, authentication_token: currentToken},
		onSuccess: function(transport){
			resp = transport.responseXML;
						
			if(!checkResp(resp)){
				return;
			}
			if (resp.getElementsByTagName("response")[0].getAttribute("status") == "ok"){
					var ordenesDiv = document.createElement("div");
				//	document.getElementById("mainContent").innerHTML="";
				//	document.getElementById("mainContent").appendChild(ordenesDiv);
					
				var ordenes=resp.getElementsByTagName("order");
				for(var i = 0; i < ordenes.length; i++)
				{
					var status = ordenes[i].getElementsByTagName("status")[0].firstChild.nodeValue;
					if(status == '1'){
						var select = document.getElementById("DispOrder")
						var option = document.createElement("option");
						option.setAttribute("value", ordenes[i].getAttribute("id"));
						option.innerHTML=ordenes[i].getAttribute("id");
						select.appendChild(option);
					}
				}
			}
			
		},
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
  });
}
function setAddressInPopUp(){
	var resp;
	
	/*currentUsr = cookie.getCookie('username');
	currentPass = cookie.getCookie('password');
	currentToken = cookie.getCookie('token');*/
	var cookie = new cookiejar("tienda_virtual");
	/*alert(cookie.getCookie('username'));*/
	if(currentUsr == '' || currentToken == '') {
		alert('hay que loguearse antes');
		return;
	}

	var req = new Ajax.Request(urlorder, {
		method: 'post',
		parameters: {method: 'GetAddressList', username: currentUsr, authentication_token: currentToken},
		onSuccess: function(transport){
			resp = transport.responseXML;
			if(!checkResp(resp)){
				return;
			}
			
				var addList = resp.getElementsByTagName('address');
					
				for(var i=0; i<addList.length; i++) {
					
					var addID = addList[i].getAttribute("id");
					var fullname = addList[i].getElementsByTagName('full_name')[0].firstChild.nodeValue;
					var addressline1 = addList[i].getElementsByTagName('address_line_1')[0].firstChild.nodeValue;
					
					var select = document.getElementById("DispAddress")
					var option = document.createElement("option");
					option.setAttribute("value",addID);
					option.innerHTML=fullname;
					option.name=addressline1;
					select.appendChild(option);
					
				}
			
		},
		
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
		
	});
};
function getOrderDetail(orderId){
		var resp;
	
	/*currentUsr = cookie.getCookie('username');
	currentPass = cookie.getCookie('password');
	currentToken = cookie.getCookie('token');*/
	/*var cookie = new cookiejar("tienda_virtual");
	alert(cookie.getCookie('username'));*/
	if(currentUsr == '' || currentToken == '') {
		alert('hay que loguearse antes');
		return;
	}
 
	var req = new Ajax.Request(urlorder, {
		method: 'get', 
		parameters: {method: 'GetOrder', username: currentUsr, authentication_token: currentToken, order_id: orderId},
		onSuccess: function(transport){
			resp = transport.responseXML;
						
			if(!checkResp(resp)){
				return;
			}
			if (resp.getElementsByTagName("response")[0].getAttribute("status") == "ok"){
					var ordenesDiv = document.createElement("div");
					document.getElementById("mainContent").innerHTML="";
					document.getElementById("mainContent").appendChild(ordenesDiv);
				 
				var orden=resp.getElementsByTagName("order")[0];
				var ordenDiv = document.createElement("div");
				ordenDiv.setAttribute("class","ordenDetailDiv");
				
				var address_id="";
				try{
					address_id = orden.getElementsByTagName("address_id")[0].firstChild.nodeValue;
				}catch(e){
				}
				var status = orden.getElementsByTagName("status")[0].firstChild.nodeValue;
				var created_date = orden.getElementsByTagName("created_date")[0].firstChild.nodeValue;
				var confirmed_date="";
				var shipped_date="";
				try{ 
					confirmed_date = orden.getElementsByTagName("confirmed_date")[0].firstChild.nodeValue;
				}catch(e){
				}
				try{
				shipped_date = orden.getElementsByTagName("shipped_date")[0].firstChild.nodeValue;
				}catch(e){
				}
					var latitude = orden.getElementsByTagName("latitude")[0].firstChild.nodeValue;
					var longitude = orden.getElementsByTagName("longitude")[0].firstChild.nodeValue;
					
					ordenDiv.setAttribute("id","orden"+orden.getAttribute("id"));
					
					var ordenNumber = document.createElement('h1');
					ordenNumber.innerHTML= "Numero De Orden:" + orden.getAttribute("id");
					ordenDiv.appendChild(ordenNumber);
					
					
			
			
					
					switch(status){
						case '4':
								var date4 = document.createElement("div");
								date4.innerHTML = "<h3>Delivered Date: </h3>" + delivered_date;
								ordenDiv.appendChild(date4);
						case '3':
								var mapcanva = document.createElement("div");
								mapcanva.setAttribute("id","map_canvas");
								mapcanva.style.width ="500px";
								mapcanva.style.height="300px";
								
								ordenDiv.appendChild(mapcanva);
								
								initialize(latitude,longitude);
								
								var lat = document.createElement("p");
								lat.innerHTML = "Longitude " + latitude;
								ordenDiv.appendChild(lat);
					
								var log = document.createElement("p");
								log.innerHTML = "Latitude " + longitude;
								ordenDiv.appendChild(log);
								
								var date3 = document.createElement("div");
								date3.innerHTML = "<h3> Shipped Date: </h3>" + "<p>" + shipped_date + "</p>";
								ordenDiv.appendChild(date3);
							
						case '2':
								var date2 = document.createElement("div");
								date2.innerHTML = "<h3> Confirmed Date </h3>" + "<p>" + confirmed_date + "</p>";
								ordenDiv.appendChild(date2);
								
/* 								var mapcanva = document.createElement("div");
								mapcanva.setAttribute("id","map_canvas");
								mapcanva.style.width ="500px";
								mapcanva.style.height="300px";
								ordenDiv.appendChild(mapcanva);
								
								
								
								var lat = document.createElement("p");
								lat.innerHTML = "Longitude " + latitude;
								ordenDiv.appendChild(lat);
					
								var log = document.createElement("p");
								log.innerHTML = "Latitude " + longitude;
								ordenDiv.appendChild(log); */
								
							
						case '1':
								var date1 = document.createElement("div");
								date1.innerHTML = "<h3> Created Date: </h3> " + "<p>" + created_date + "</p>";
								ordenDiv.appendChild(date1);
							break;
					}
				
					var itemsDetail = document.createElement("h3");
					itemsDetail.innerHTML = "Items Details: ";
					ordenDiv.appendChild(itemsDetail);
					
					var items = orden.getElementsByTagName("item");
					var table = document.createElement("table");
				
					var tableheader = document.createElement("tr");
					
					var asd = document.createElement("th");
					asd.innerHTML ="ID";
					tableheader.appendChild(asd);
					
					var asd = document.createElement("th");
					asd.innerHTML ="Name";
					tableheader.appendChild(asd);
					
					var asd = document.createElement("th");
					asd.innerHTML ="Quantity";
					tableheader.appendChild(asd);
					
					var asd = document.createElement("th");
					asd.innerHTML ="Price";
					tableheader.appendChild(asd);
					
					var asd = document.createElement("th");
					asd.innerHTML ="";
					tableheader.appendChild(asd);
					
					table.appendChild(tableheader);
					

					var tablebody = document.createElement("tbody");
					table.appendChild(tablebody);
					var totalacum = 0;
					for( var i = 0; i< items.length ; i++){
						var prodCOnt = document.createElement("tr");
						prodCOnt.setAttribute("class","prodCont" + (i%2));
						var prodId = items[i].getElementsByTagName("product_id")[0].firstChild.nodeValue;
						var cant = items[i].getElementsByTagName("count")[0].firstChild.nodeValue;
						var price = items[i].getElementsByTagName("price")[0].firstChild.nodeValue;
						
						var prodIdDiv = document.createElement("td");
						prodIdDiv.setAttribute("class","prodDesc");
						prodIdDiv.innerHTML = prodId;
						prodCOnt.appendChild(prodIdDiv);
						
						var nameprod = document.createElement("td");
						nameprod.setAttribute("id","prodName"+i);
						nameprod.setAttribute("class","prodName");
						prodCOnt.appendChild(nameprod);
						setProductName(prodId,i);
						
						var cantDiv = document.createElement("td");
						cantDiv.innerHTML = cant;
						cantDiv.setAttribute("class","prodDesc");
						prodCOnt.appendChild(cantDiv);

						
						var priceDiv = document.createElement("td");
						priceDiv.innerHTML = price;
						priceDiv.setAttribute("class","prodDesc");
						prodCOnt.appendChild(priceDiv);
						
						
						totalacum = price * cant + totalacum;
						
						if(status == '1'){
							var eleminartd = document.createElement("td"); 
							var eliminarButton = document.createElement("input");
							eliminarButton.setAttribute("type","button");
							eliminarButton.setAttribute("onClick","deleteOrderItem(\""+ prodId +"\" , \"" + cant +"\" , \"" + orderId+ "\" );");
							eliminarButton.setAttribute("value","Eliminar");
							eleminartd.appendChild(eliminarButton);
							prodCOnt.appendChild(eleminartd);
						}
						tablebody.appendChild(prodCOnt);
					}
					ordenDiv.appendChild(table);
					var acum = document.createElement("div");
					acum.innerHTML = "<h3> Total: </h3>" + '$' + totalacum;
					ordenDiv.appendChild(acum);
					
					if( status == '1' && totalacum != 0){
							var confirmar = document.createElement("input");
							confirmar.setAttribute("type","button");
							confirmar.setAttribute("onClick","displayComfirmOrder(\""+ orderId +"\");");
							confirmar.setAttribute("value","Confirmar");
							ordenDiv.appendChild(confirmar)
						}
					
				
		/*falta poner la logica de que si esta creada hay que confirmarla */
/*					switch(status){
						case '4':
							Transportada.appendChild(ordenDiv);
							break;
						case '3':
							Entregadas.appendChild(ordenDiv);
						case '2':
							Creada.appendChild(ordenDiv);
						case '1':
							Confirmada.appendChild(ordenDiv);
						}*/
						
					
				
			}
			ordenesDiv.appendChild(ordenDiv);
			if(status == '3' || status == '4'){
				initialize(latitude,longitude);
			}
		},
		onFailure: function(){ alert('Sorry, we have a little problem with the server, please try later')}
  });
}

function setProductName(productId,i) {
//alert("estoy en setname\n id prod = " + productId);
	var reqn = new Ajax.Request(
			urlcatalog,
			{
				method : 'get',
				parameters : {
				method : 'GetProduct',
				product_id : productId,
				},
				onSuccess : function(transport) {

					var response = transport.responseXML || "no response text";
					var product = response.getElementsByTagName("product")[0];
					var productNameDiv = document.getElementById("prodName"+i);
					
//					productsDiv.innerHTML="";
					productNameDiv.innerHTML = product.getElementsByTagName("name")[0].firstChild.nodeValue;
				},
				onFailure : function() {
					alert('Problems on Ajax Request')
				}

			});
}
function ordernumberSelected(){
	var select = document.getElementById("DispOrder");
	if(select.value == -1){
		//validar el error;
		return;
	}
	return select.value;
}
function AddIdSelected(){
	var select = document.getElementById("DispAddress");
	if(select.value == -1){
		//validar el error;
		return;
	}
	return select.value;
}

function ConfirmOrder (orderId,addressID){
	if( addressID )
	var reqn = new Ajax.Request(
		urlorder,
		{
			method : 'post',
			parameters : {
			method : 'ConfirmOrder',
			authentication_token: currentToken,
			username: currentUsr,
			order_id: orderId,
			address_id : addressID
			},
			onSuccess : function(transport) {

				var response = transport.responseXML || "no response text";
				if(response.getElementsByTagName("response")[0].getAttribute("status") == 'ok'){
					displayAlert("Order Number: " + orderId + " confirmed");
					}
			},
			onFailure : function() {
				alert('Problems on Ajax Request')
			}

			});
}

